﻿using System;
using System.IO;
using Microsoft.Coding4Fun.TweetCraft.Twitter;
using Microsoft.Coding4Fun.TweetCraft.Wow;

using NUnit.Framework;

namespace Microsoft.Coding4Fun.TweetCraft.Tests
{
    [TestFixture]
    public class TwitterUserPictureServiceTest
    {
        private ITwitterUserPictureService _userPictureService;

        [SetUp]
        public void SetUp()
        {
            // Initialize a new instance of the user picture service
            _userPictureService = new TwitterUserPictureService<FileDownloadClient, WorldOfWarcraftTargaConverter>();
        }
        
        [Test]
        public void GetUserPicturePathTest()
        {
            // Set the location where user pictures should be saved
            _userPictureService.UserPictureDirectory = Environment.CurrentDirectory;

            // Construct a Twitter User object with a user picture url
            var user = new User
                           {
                               Id = 12345,
                               ScreenName = "rgabostyle",
                               ImageUrl = new Uri("rgabostyle.jpg", UriKind.Relative)
                           };

            // Get the path to the picture of the tweet's user
            string userPicturePath = _userPictureService.GetUserPicturePath(user);

            // Assert that the path is not null and there's a TGA file there
            Assert.IsNotNull(userPicturePath);
            Assert.AreEqual(".tga", Path.GetExtension(userPicturePath));
            Assert.IsTrue(File.Exists(userPicturePath));

            // Delete the user picture to revert to original state
            File.Delete(userPicturePath);
        }
    }
}
